package com.example.springcloud.service;

import com.example.springcloud.pojo.Dept;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author :lihao
 * @date :2020/12/01
 * @description : 服务降级，回调工厂
 */
@Component
public class DeptClientServiceFallbackFactory implements FallbackFactory {

    @Override
    public DeptClientService create(Throwable throwable) {
        return new DeptClientService() {
            @Override
            public Dept queryDeptById(Long id) {
                return new Dept()
                        .setDeptNo(id)
                        .setDeptName("not have info,this server is closed")
                        .setDbSource("not have database");
            }

            @Override
            public boolean addDepartment(Dept dept) {
                return false;
            }

            @Override
            public List<Dept> queryAllDept() {
                return null;
            }
        };
    }
}
